import {mavonEditor} from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'

export let data = {
  components: {
    mavonEditor
  },
  data () {
    return {
      search: {
        type: 'contract',
        category: '',
      },
      cateList: [],
      editForm: {
        content: '',
        doc: '',
        id: 0,
        type: '',
        category: ''
      }
    }
  },
  methods: {
    findPage: function () {
      this.$api.dict.findListCate({str: this.search.type}).then((res) => {
        if (res.isSuccess) {
          this.cateList = res.body
        }
      }).catch(() => {
        this.$message.error(res.msg)
      })
    },
    changeType: function () {
      if(!this.search.category){
        this.$message.error("请选择需要配置的内容")
        return
      }
      this.editForm.content = ''
      this.editForm.doc = ''
      this.editForm.id = 0
      this.editForm.type = this.search.type
      this.editForm.category = this.search.category
      this.$api.configtxt.listTxt(this.search).then((res) => {
        if (res.isSuccess == true || res.body[0]) {
          this.editForm.content = res.body[0].content
          this.editForm.id = res.body[0].id
          this.editForm.doc = res.body[0].doc
        }
      }).catch(() => {
        this.$message.error(res.msg)
      })
    },
    changeData(value, render) {
      this.editForm.content = render;
    },
    subForm: function(){
      this.$api.configtxt.saveTxt(this.editForm).then((res) => {
        if (res.isSuccess == true) {
          this.editForm.id=res.body
          this.$message.success("保存成功")
        }
      }).catch(() => {
        this.$message.error(res.msg)
      })
    }
  },
  computed: {
    prop () {
      let ss = {
        subfield: true,// 单双栏模式
        defaultOpen: 'preview',//edit： 默认展示编辑区域 ， preview： 默认展示预览区域
        editable: true,
        toolbarsFlag: true,
        scrollStyle: true
      }
      return ss
    }
  },
  mounted () {
    this.findPage()
  }
}
